import Vue from "vue";
import {actions} from '../base';

let url = 'admin/api/apk';

export default {
    namespaced: true,
    state: {
        all: [],
        baseList: [],
        options: {
            status: [
                {label: '处理中', value: 0, class: 'info'},
                {label: '已生成', value: 1, class: 'warning'},
                {label: '已上传', value: 2, class: 'primary'},
            ]
        },
        request: {
            all: false,
        }
    },
    mutations: {
        SET_ALL (state, data) {
            state.all = data;
        },
        SET_REQUESTING (state, name) {
            state.request[name] = true;
        },
        SET_REQUESTED (state, name) {
            state.request[name] = false;
        },
        SET_BASE_LIST (state, data) {
            state.baseList = data;
        },
    },
    actions: Object.assign({}, actions(url), {
        BaseList ({commit}) {
            return new Promise((resolve, reject) => {
                Vue.axios.get(`${url}/base`).then(res => {
                    commit('SET_BASE_LIST', res.data.data);
                    return resolve(res);
                }).catch(error => {
                    return reject(error);
                });
            });
        },
        DestroyBase({commit}, name) {
            return Vue.axios.delete(`${url}/base/${name}`);
        },
        BatchUpdate({commit}, data) {
            return Vue.axios.put(`${url}/batch`, data);
        },
    }),
};
